$(".top_left").click(function () {
    history.back()
})
//    加减计数器
$(document).ready(function () {
    $(".add").click(function() {
        var t = $(this).parent().find('input[class*=numnum]');
        if(t.val()==""||undefined||null){
            t.val(1);
        }
        t.val(parseInt(t.val()) + 1)
        setTotal();
    });
    $(".reduce").click(function() {
        var t = $(this).parent().find('input[class*=numnum]');
        if(t.val()==""||undefined||null){
            t.val(1);
        }
        t.val(parseInt(t.val()) - 1)
        if(parseInt(t.val()) < 1) {
            t.val(1);
        }
        setTotal();
    })
    $(".numnum").keyup(function(){
        var t = $(this).parent().find('input[class*=numnum]');
        if(parseInt(t.val())==""||undefined||null || isNaN(t.val())) {
            t.val(1);
        }
        setTotal();
    });
    function setTotal() {
        var s = 0;
        var t = $(".numnum").val();
        var p = $(".price").text();
        s += parseInt(t) * parseFloat(p);
        $(".color").html(s.toFixed(2));
    }
});
//单选框的值var a = $("input[name='danxuan']:checked").val();
$(".pay_btn").click(function () {
    $(".pay_btn").css("background","#f96652");
        var agreement;
        if($(".agree_txt").is(":hidden")){
            agreement=0
        }else{
            agreement=1
        };
        if(agreement==0){
            alert("请同意协议");
            return
        }
        //所需参数如下
        var pagehash=$.trim($(".pagehash").val());
        var id=$.trim($(".id_id").val());
        var type=$.trim($(".pagehash2").val());
        var mobile=$.trim($(".mobile").val());
        var qq=$.trim($(".qqq_q").val());
        var job=$.trim($(".job option:selected").text());
        var role_name=$.trim($(".role_name").val());
        var service_id=$.trim($(".service_id option:selected").val());
        var sex=$.trim($(".sex option:selected").val());
        var num=$.trim($(".numnum").val());
        var price=$.trim($(".price").html());
        var pay_mode;
       if($(".cheeck_img_img").is(":hidden")){
           pay_mode=2  //index为2是微信支付
       }else {
           pay_mode=1   //index为1是支付宝支付
       }

    if(type==4){ //账号
    if(agreement==""||mobile==""||qq==""||role_name==""||job==""||num==""||role_name==""||job==""){
        alert("必要字段不能为空");
        return;
    }else {
        console.log("账号字段满足情况")
    }
}
    if(type==5){  //游戏币
    if(agreement==""||mobile==""||qq==""||role_name==""||job==""||num==""||service_id==""||sex==""){
        alert("必要字段不能为空");
        return;
    }else{
        console.log("游戏币字段满足情况")
    }
   }
    if(type==6){ //道具
    if(agreement==""||mobile==""||qq==""||num==""||price==""||sex==""){
        alert("必要字段不能为空");
        return
    }else{
        console.log("道具字段满足情况")
    }
}
    var data={
        pagehash:pagehash,
            type:type,
            agreement:agreement,
            mobile: mobile,
            qq: qq,
            role_name:role_name,
            job:job,
            sex:sex,
            service_id:service_id,
            num:num,
            id:id,
            price:price,
            pay_mode:pay_mode
    }
    console.log(data)
    //确认购买订单订单就接口开始了
        $.ajax({
            url: "http://m.66173.com/trading_center.php?act=confirm_pay",
            type: "POST",
            data: {
                pagehash:pagehash,
                type:type,
                agreement:agreement,
                mobile: mobile,
                qq: qq,
                role_name:role_name,
                job:job,
                sex:sex,
                service_id:service_id,
                num:num,
                id:id,
                price:price,
                pay_mode:pay_mode
            },
            dataType: "text",
            async:false,
            success:function (res) {
                console.log(res);
                console.log("成功");
            },
            error:function (res) {
                console.log(res);
            }
        })
});
$(".label_agree").click(function () {
    if($(".agree_txt").is(":hidden")){
        $(".agree_txt").show();
        $(".agree_txt4").hide()
    }else{
        $(".agree_txt4").show();
        $(".agree_txt").hide()
    }
});
function aaa() {
    if($(".cheeck_img_img").is(":hidden")){
        $(".cheeck_img_img").show();
        $(".cheeck_img_img2").hide();
        $(".cheeck_img_img3").hide();
        $(".cheeck_img_img4").show();
    }
}
function bbb() {
    if($(".cheeck_img_img3").is(":hidden")){
        $(".cheeck_img_img2").show();
        $(".cheeck_img_img").hide();
        $(".cheeck_img_img3").show();
        $(".cheeck_img_img4").hide();
    }
}
//解密base64后端数据开始
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1, 0, 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;
    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
        /* c1 */
        do {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while(i < len && c1 == -1);
        if(c1 == -1)
            break;
        /* c2 */
        do {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while(i < len && c2 == -1);
        if(c2 == -1)
            break;
        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
        /* c3 */
        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if(c3 == 61)
                return out;
            c3 = base64DecodeChars[c3];
        } while(i < len && c3 == -1);
        if(c3 == -1)
            break;
        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
        /* c4 */
        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if(c4 == 61)
                return out;
            c4 = base64DecodeChars[c4];
        } while(i < len && c4 == -1);
        if(c4 == -1)
            break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}
//解密base64后端数据结束

